<template>
  <div class="main-box">
    <el-container class="container">
      <el-aside :width="isFold ? '60px' : '210px'" class="aside">
        <MainMenu :isFold="isFold" :menuList="userStore.routesAsync"> </MainMenu>
      </el-aside>
      <el-container style="height: 100%">
        <el-header height="50px" class="header">
          <el-card shadow="hover" class="box-card" style="height: 50px">
            <MainHeader @foldChange="foldChange"></MainHeader>
          </el-card>
        </el-header>
        <el-main class="body">
          <MainBody></MainBody>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useUserStore } from '@/store/userStore'
import MainMenu from '@/components/main/MainMenu.vue'
import MainHeader from '@/components/main/MainHeader.vue'
import MainBody from '@/components/main/MainBody.vue'

const userStore = useUserStore()

const isFold = ref(false)

// 通过自定义事件，获取头部触发的状态值，改变侧边栏的大小
const foldChange = (val: boolean) => {
  isFold.value = val
}

onMounted(async () => {
  try {
    if (!userStore.userInfoDetail) {
      // 不存在在获取数据

      // 进入后台管理界面的时候立即获取用户信息
      await userStore.getUserInfoDetailAction()
      // 必须先获取用户数据在获取菜单
      await userStore.getRoutes()
    }
  } catch (error) {}
})
</script>

<style lang="scss" scoped>
.main-box {
  height: 100%;
}
.container,
.aside,
.body {
  height: 100%;
  :deep(.el-card) {
    height: 100%;
  }
}
.aside {
  transition: width 0.5s ease;
  will-change: width;
}
.header {
  :deep(.el-card__body) {
    padding: 5px 20px 0;
  }
}
</style>
